package org.moonshiner.ctci.c1.q4;

public class SpaceChanger {

	public String mySpaceChanger(String inputString, int spaceCount){
		
		char[] chars = inputString.toCharArray();
		
		char[] resultChars = new char[inputString.length() + spaceCount * 2];
		int index = 0;
		
		for (int i = 0; i < chars.length; i++) {
			
			if(chars[i] == ' '){
				pasteSpace(resultChars, index);
				index += 3;
			}else{
				resultChars[index] = chars[i];
				index++;
			}
		}
		
		return new String(resultChars);
	}

	private void pasteSpace(char[] resultChars, int index) {
		
		resultChars[index++] = '%';
		resultChars[index++] = '2';
		resultChars[index++] = '0';
		
	}
	
	
}
